package io.jee.medusa.orm.pager.support;

import org.springframework.util.StringUtils;

import io.jee.medusa.orm.pager.OrderByBuilder;

public class DataGridSupport extends ConditionSupport {

	private int page;
	private int rows;
	private String sort;
	private String order;

	@Override
	public void orderBy(OrderByBuilder builder) {
		if(StringUtils.hasText(sort)&&StringUtils.hasText(order)){
			builder.on(sort, order);
		}
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		super.getPager().setIndex((page-1)*rows);
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		super.getPager().setIndex((page-1)*rows);
		super.getPager().setItemSize(rows);
		this.rows = rows;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

}
